<?php

/*
 * @author Ebrain Cedeno <ebraincedeno@gmail.com>
 */

class TDatePicker extends TWidget{
    
    public $Text;
    public $Time;
    public $Format = "dd-mm-yy";
    
    public function __construct($name = __CLASS__) {
        parent::__construct($name);
        $this->Time = time();
        $this->Text = date("d-m-Y");
        $this->Width = 200;
        $this->Height = 25;
    }
    
    public function show(){
        
        if ($this->Visible == true){
            
            if (!array_key_exists('style', $this->OptionsAditional)){
                $this->OptionsAditional['style'] = array('width:'.$this->Width.'px','height:'.$this->Height.'px');
            }
            else{
                $this->OptionsAditional['style'][] = 'width:'.$this->Width.'px';
                $this->OptionsAditional['style'][] = 'height:'.$this->Height.'px';
            }
            
            //dandole formato a la fecha en php
            
            if (strtolower($this->Format) == 'dd-mm-yy'){
                $this->Text = date("d-m-Y",$this->Time);
            }
            else{
                $this->Text = date("Y-m-d",$this->Time);
            }
            
            
            
            return '
                <script type="text/javascript">
                     $(function() {
                        $.datepicker.setDefaults( $.datepicker.regional[ "es" ] );
                        $( "#'.$this->Id.'" ).datepicker($.datepicker.regional[ "es" ]);
                        $( "#'.$this->Id.'" ).datepicker( "option", "dateFormat", "'.$this->Format.'");
                        $( "#'.$this->Id.'" ).datepicker("setDate",\''.$this->Text.'\');


                     });
                </script>'."\n".'
                    <input name="'.$this->Name.'" id="'.$this->Id.'" type="text" value="" '.$this->getOptionsAditional().'/>
                ';
        }
        
        
    }
    
    
}

?>
